package com.situ.shoplook.common.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.shoplook.common.mapper.GoodsInfoMapper;
import com.situ.shoplook.common.model.GoodsInfo;
import com.situ.shoplook.common.service.GoodsInfoService;
import org.jasypt.util.password.PasswordEncryptor;
import org.jasypt.util.password.StrongPasswordEncryptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import java.util.List;

/**
* @Author xinchen
 * @Date: 2024/08/30/ 22:38
 * @Description
 */
@Service
public class GoodsInfoServiceImpl implements GoodsInfoService {
    private GoodsInfoMapper goodsInfoMapper;

    @Autowired
    public void setGoodsInfoMapper(GoodsInfoMapper goodsInfoMapper) {
        this.goodsInfoMapper = goodsInfoMapper;
    }
    /**
     * add
     */
    @Override
    public int save(GoodsInfo goodsInfo) throws Exception {

        return this.goodsInfoMapper.insertSelective(goodsInfo);
    }

    /**
     * 更新
     * @throws Exception
     */
    @Override
    public int update(GoodsInfo goodsInfo) throws Exception {
        return goodsInfoMapper.updateByPrimaryKeySelective(goodsInfo);
    }

    /**
     * 删除
     * @return
     */
    @Override
    public int remove(Integer[] ids) {
        int count =  goodsInfoMapper.deleteByIds(ids);
        return count;
    }

    /**
     * 分页
     * @return
     */
    @Override
    public PageInfo searchByPage(Integer page, Integer limit, GoodsInfo goodsInfo)  {
        try(Page<?> __ = PageHelper.startPage(page, limit)) {
            List<GoodsInfo> list = goodsInfoMapper.search(goodsInfo);
            PageInfo pageInfo = new PageInfo<>(list);
            return pageInfo;
        }
    }

    @Override
    public GoodsInfo getGoodsById(Long goodsId) {
        return goodsInfoMapper.selectByPrimaryKey(goodsId);
    }

    @Override
    public List<GoodsInfo> findByHotGoodses() {
        return goodsInfoMapper.findByHotGoodses();
    }
}
